package com.ouyeel.wlxer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ouyeel.wlxer.R;
import com.ouyeel.wlxer.bean.ManualOut;

import java.util.List;

/**
 * Created by rankaifeng on 2017/10/30.
 */

public class ManualClockingAdapter extends BaseAdapter {
    public int selectPosition = -1;
    private List<ManualOut.CarList> carListList;
    private Context mContext;
    private LayoutInflater inflater;

    public ManualClockingAdapter(List<ManualOut.CarList> carListList, Context mContext) {
        this.carListList = carListList;
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return carListList.size();
    }

    @Override
    public Object getItem(int position) {
        return carListList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_carnumber_item, null);
            viewHolder = new ViewHolder();
            viewHolder.mImageView = convertView.findViewById(R.id.img_check);
            viewHolder.tvCarNumber = convertView.findViewById(R.id.tv_car_number);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvCarNumber.setText(carListList.get(position).getCarNum());
        if (selectPosition == position) {
            viewHolder.mImageView.setImageResource(R.drawable.b_radio_d);
        } else {
            viewHolder.mImageView.setImageResource(R.drawable.b_radio);
        }
        return convertView;
    }

    class ViewHolder {
        TextView tvCarNumber;
        ImageView mImageView;
    }
}
